import moment from 'moment';

export function GetRangePickerName({
  originName,
  mode
}: {
  originName: string;
  mode: string;
}) {
  const modeNames: IterateAny = {
    date: '（天）',
    time: '（小时）'
  };
  return originName + (modeNames[mode] || '');
}

// 间隔30分钟
export function getNextTime(cur: moment.Moment) {
  const newDate = moment(cur).add(30, 'minutes');
  return newDate;
}

// 间隔30分钟
export function getPrevTime(cur: moment.Moment) {
  const newDate = moment(cur).subtract(30, 'minutes');
  return newDate;
}

export function getDefaultHM(
  cur?: moment.Moment,
  type: 'next' | 'prev' = 'next'
) {
  if (!cur) {
    const date = moment();
    if (date.minutes() >= 30) {
      //转换值，只允许30 和 00
      return moment(date.format('YYYY-MM-DD HH:30'));
    } else {
      return moment(date.format('YYYY-MM-DD HH:00'));
    }
  }
  let result;
  if (type === 'prev') {
    result = getPrevTime(cur);
  } else {
    result = getNextTime(cur);
  }

  return moment(result, 'YYYY-MM-DD HH:mm');
}

// 时间和分钟是不是最大
export function isMaxHM(cur?: moment.Moment) {
  if (cur?.minutes() === 30 && cur.hours() === 23) {
    return true;
  }
  return false;
}
export function isMinHM(cur?: moment.Moment) {
  if (cur?.minutes() === 0 && cur.hours() === 0) {
    return true;
  }
  return false;
}
export function isMinM(cur?: moment.Moment) {
  if (cur?.minutes() === 0) {
    return true;
  }
  return false;
}

export function isMaxM(cur?: moment.Moment) {
  if (cur?.minutes() === 30) {
    return true;
  }
  return false;
}
